<template>
  <!-- 维修管理 -->
  <el-container>
    <el-header>
      <div class="left-panel">
        <!-- <el-button
          type="primary"
          icon="el-icon-plus"
          @click="add"
          v-auth-button="['add/returnProduct']"
        ></el-button> -->
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-input
            v-model="searchValue.name"
            placeholder="合同名称"
            clearable
          ></el-input>
          <el-select
            v-model="searchValue.status"
            placeholder="请选择维修状态"
            style="width: 100%"
            clearable
          >
            <el-option label="未完成" :value="0" />
            <el-option label="已完成" :value="1" />
          </el-select>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upsearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        row-key="id"
        stripe
        @row-dblclick="handleRowDblclick"
      >
        <el-table-column label="ID" prop="id" width="50"></el-table-column>
        <el-table-column label="名称" prop="repairName"> </el-table-column>
        <el-table-column label="负责人" prop="username"> </el-table-column>
        <el-table-column
          label="预计完成维修时间"
          prop="deadline"
          width="250"
        ></el-table-column>
        <el-table-column label="备注" prop="remark"></el-table-column>
        <el-table-column label="维修状态" prop="status" width="200">
          <template #default="scope">
            <!-- 0未完成，1已完成-->
            <p v-if="scope.row.status == 0">未完成</p>
            <p v-if="scope.row.status == 1" style="color: #67c23a">已完成</p>
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="center" width="250">
          <template #default="scope">
            <el-button-group>
              <el-button
                text
                type="primary"
                size="small"
                @click="table_confirm(scope.row, scope.$index)"
                v-if="scope.row.status == 0"
                v-auth-button="['confirm/repairManagement']"
                >确认完成</el-button
              >

              <el-button
                text
                type="primary"
                size="small"
                @click="table_show(scope.row, scope.$index)"
                v-auth-button="['show/repairManagement']"
                >查看</el-button
              >
              <el-popconfirm
                title="确定删除吗？"
                @confirm="table_del(scope.row, scope.$index)"
                v-if="scope.row.status == 0"
              >
                <template #reference>
                  <el-button
                    text
                    type="primary"
                    size="small"
                    v-auth-button="['delete/repairManagement']"
                    >删除</el-button
                  >
                </template>
              </el-popconfirm>
            </el-button-group>
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
</template>
<script>

export default {
  name: 'returnGoods',
  data () {
    return {
      apiObj: this.$API.produce.repair.getRepairList,
      searchValue: {
        name: null,
        status: null
      },
    }
  },

  methods: {
    // 确认维修
    table_confirm (row) {
      this.$confirm(`请确认【${row.repairName}】所维修的产品是否已完成, 请问是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        let res = await this.$API.produce.repair.confirmRepair.post({ id: row.id, status: 1 })
        if (res.code == 200) {
          this.$refs.table.refresh()
          this.$message.success("操作成功")
        }
      }).catch(() => {

      })
    },

    //查看
    table_show (row) {
      this.$router.push({
        path: '/produce/repairManagement/repairDetail',
        query: {
          id: row.id
        }
      })
    },
    //删除 
    async table_del (row) {
      let data = {
        ids: row.id,
      }
      var res = await this.$API.produce.repair.deleteRepair.post(data)
      if (res.code == 200) {
        this.$refs.table.refresh()
        this.$message.success("删除成功")
      }
    },

    //搜索
    upsearch () {
      this.$refs.table.upData(this.searchValue)
    },

    // 双击表格
    handleRowDblclick (row) {
      this.table_show(row)
    }

  }
}
</script>

<style>
</style>